<template>
  <div class="recommendAdvertstyle">
    <!-- 标题 -->
    <h2>{{ datas.text }}</h2>
    <span style="margin-top:10px; display:block; font-weight:bold;">组件高度：{{ datas.componHight }}</span>
    <p style="color: #323233; font-size: 14px">背景图片</p>

    <div style="height: 10px"></div>

    <p style="color: #969799; font-size: 12px">
      建议尺寸：750x370 像素，尺寸不匹配时，图片将被压缩或拉伸以铺满画面
    </p>
    
    <div style="height: 10px"></div>

    <!-- 背景图 -->
    <div class="backgroundImg" @click="uploadI()">
      <img draggable="false" v-if="!datas.bakcgroundImg" src="../../../../assets/images/backimg.png" alt="" />
      <img draggable="false" v-else :src="datas.bakcgroundImg" alt="" />
      <p>更换图片</p>
    </div>

    <div style="height: 30px"></div>

    <el-form label-width="80px" :model="datas" size="small" :rules="rules">
      <!-- 学科名称 -->
      <el-form-item label="学科名称" class="lef" prop="name">
        <el-input v-model="datas.name" placeholder="请填写学科名称" maxlength="20" clearable></el-input>
      </el-form-item>
      <select-link @selectThisLink="selectThisLink" @clearThisLink="clearThisLink" :linktypeurl="datas.apiUrl" />
    </el-form>

    <!-- 上传图片 -->
    <uploadimg ref="upload" @uploadInformation="uploadInformation" />
  </div>
</template>
<script>
import uploadimg from "../../../uploadImg"; // 图片上传
import SelectLink from "../../../selectLink";
export default {
  name: "RecommendAdvertstyle",
  props: {
    datas: Object,
  },
  components: {
    uploadimg,
    SelectLink
  },
  data() {
    return {
      interurl: "",
      rules: {
        name: [{ required: true, message: "请输入学科名称", trigger: "blur" }],
      },
    };
  },
  methods: {
    /* 上传图片 */
    uploadI() {
      this.$refs.upload.showUpload();
    },
    // 提交
    uploadInformation(res) {
      this.datas.bakcgroundImg = res;
    },
    selectThisLink(resu) {
      this.datas.apiUrl = resu.url;
    },
    clearThisLink (index) {
      this.datas.apiUrl = '';
    }
  },
  created() {
    this.interurl = this.datas.apiUrl;
  }
};
</script>
<style lang="scss" scoped>
.recommendAdvertstyle {
  width: 100%;
  position: absolute;
  left: 0;
  top: 0;
  padding: 0 10px 20px;
  box-sizing: border-box;
  /* 标题 */
  h2 {
    padding: 24px 16px 24px 0;
    margin-bottom: 15px;
    border-bottom: 1px solid #f2f4f6;
    font-size: 18px;
    font-weight: 600;
    color: #323233;
  }
  /* 背景图 */
  .backgroundImg {
    display: inline-flex;
    align-items: center;
    cursor: pointer;
    width: 60px;
    height: 60px;
    position: relative;
    background: #f2f4f6;

    img {
      width: 100%;
      height: auto;
    }

    p {
      position: absolute;
      left: 0;
      bottom: 0;
      width: 100%;
      height: 20px;
      font-size: 12px;
      color: #fff;
      background: rgba(0, 0, 0, 0.5);
      text-align: center;
      line-height: 20px;
    }
  }
}
</style>
